﻿Imports System.Data.OleDb
Partial Public Class UserInformation
    Inherits System.Web.UI.Page
    Dim FolderName As String = "Images/"
    Dim userId As Int16
    Dim Tokan As Boolean


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        findDetailInTbl()
    End Sub

    Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Submit.Click


        If Tokan = True Then
        Else

            Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
            Dim qry As String = "INSERT INTO UserDetails (UserName,Gender,Age,HFno,County,PostCode,City,Photo) VALUES (@UserName,Gender,Age,HFno,County,PostCode,City,Photo)"
            Dim cmd As New OleDbCommand(qry, con)
            Dim Temp As String = Request.MapPath(FolderName & Me.photo_upload.FileName)
            Me.photo_upload.SaveAs(Temp)
            Dim S As String = FolderName & Me.photo_upload.FileName
            cmd.Parameters.AddWithValue("UserName", User.Identity.Name)
            cmd.Parameters.AddWithValue("Gender", Me.gendre_list.SelectedValue)
            cmd.Parameters.AddWithValue("Age", Me.tb_age.Text)
            cmd.Parameters.AddWithValue("HFno", Me.HNFno_tb.Text)
            cmd.Parameters.AddWithValue("County", Me.county_tb.Text)
            cmd.Parameters.AddWithValue("PostCode", Me.tb_PostCode.Text)
            cmd.Parameters.AddWithValue("City", Me.tb_city.Text)
            cmd.Parameters.AddWithValue("Photo", S)
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
            MsgBox("Now you are ready to go with PetsCare!!!!", MsgBoxStyle.OkOnly, "Welcome To PetsCare!")
            Response.Redirect("UserPage.aspx")

        End If



    End Sub

    Function getUserID()
        Dim Uid As Int16
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        con.Open()
        Dim oledbcmd As New OleDbCommand("SELECT * From aspnet_Users where UserName = @Username", con)
        oledbcmd.Parameters.AddWithValue("@Username", User.Identity.Name)
        Dim dr As OleDbDataReader = oledbcmd.ExecuteReader()
        dr.Read()
        Uid = dr("UserId")
        Return Uid
    End Function

    Sub findDetailInTbl()
       
        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())
        con.Open()
        Dim cmdtxt As String = "Select * from UserDetails where UserName= '" + User.Identity.Name + "'"
        Dim cmd As New OleDbCommand(cmdtxt, con)

        Dim dr As OleDbDataReader = cmd.ExecuteReader()

        While dr.Read()
            If dr.HasRows = True Then
                Me.tb_age.Text = dr("Age")
                'Me.tb_city.Text = dr("City")
                Me.tb_PostCode.Text = dr("PostCode")
                Me.county_tb.Text = dr("County")
                Me.HNFno_tb.Text = dr("HFno")
                Me.Image2.ImageUrl = dr("Photo")
            Else
                Tokan = False
            End If
        End While
    End Sub
End Class